$(document).ready(function() {
	getEmpTasks("unchecked_task_table","d",1);
});

function getEmpTasksWithUncheckedState() {
	$.ajax({
		type: "get",
		dataType: "json",
		cache: false,
		url: "getAllEmpTasks",
		data: {
			taskState: 1
		},
		success: function(data) {
			console.log(data);

			for(var i = 0; i < data.length; i++) {
				if(data[i].taskRealStartTime == null) {
					data[i].taskRealStartTime = "-";
				} else {
					data[i].taskRealStartTime.replace("T", " ");
				}
				if(data[i].taskRealEndTime == null) {
					data[i].taskRealEndTime = "-";
				} else {
					data[i].taskRealEndTime = data[i].taskRealEndTime.replace("T", " ");
				}
				if(data[i].taskPlanStartTime == null) {
					data[i].taskPlanStartTime = "-";
				} else {
					data[i].taskPlanStartTime = data[i].taskPlanStartTime.replace("T", " ");
				}
				if(data[i].taskPlanEndTime == null) {
					data[i].taskPlanEndTime = "-";
				} else {
					data[i].taskPlanEndTime = data[i].taskPlanEndTime.replace("T", " ");
				}
				var html = "<tr><td>" + (i + 1) + "</td>" +
					"<td>" + data[i].pmProjectInfo.pname + "</td>" +
					"<td>" + data[i].taskName + "</td>" +
					"<td>" + data[i].motusEmpInfoByUserId.name+ "</td>" +
					"<td>" + data[i].taskPlanStartTime + "</td>" +
					"<td>" + data[i].taskPlanEndTime + "</td>" +
					"<td>" + data[i].taskRealEndTime + "</td>" +
					"<td style='font-size: 12px;'><a href='checkEmpTask?taskId="+data[i].taskId+"' style='color:rgb(0,170,255);'><span class='glyphicon glyphicon-zoom-in'></span> 详情</a></td>" +
					"</tr>";
				$("#unchecked_task_table").append(html);
			}
		}
	});

}

function getEmpTasks(projectDivName, meetingDivName,taskState) {
	$.ajax({
		type: "get",
		projectTasksType: "json",
		async: false,
		cache: false,
		url: "getAllEmpTasks",
		data: {
			taskState: taskState
		},
		success: function(data) {
			console.log(data);
			var projectTasks=data.projectTasks;
			var meetingTasks=data.meetingTasks;

			for(var i = 0; i < projectTasks.length; i++) {
//				if(projectTasks[i].taskRealStartTime == null) {
//					projectTasks[i].taskRealStartTime = "-";
//				} else {
//					projectTasks[i].taskRealStartTime = projectTasks[i].taskRealStartTime.replace("T", " ");
//				}
				if(projectTasks[i].taskRealEndTime == null) {
					projectTasks[i].taskRealEndTime = "-";
				} else {
					projectTasks[i].taskRealEndTime = projectTasks[i].taskRealEndTime.replace("T", " ");
				}
				if(projectTasks[i].taskPlanStartTime == null) {
					projectTasks[i].taskPlanStartTime = "-";
				} else {
					projectTasks[i].taskPlanStartTime = projectTasks[i].taskPlanStartTime.replace("T", " ");
				}
				if(projectTasks[i].taskPlanEndTime == null) {
					projectTasks[i].taskPlanEndTime = "-";
				} else {
					projectTasks[i].taskPlanEndTime = projectTasks[i].taskPlanEndTime.replace("T", " ");
				}
				var html = "<tr><td>" + (i + 1) + "</td>" +
					"<td>" + projectTasks[i].pmProjectInfo.pname + "</td>" +
					"<td>" + projectTasks[i].taskName + "</td>" +
					"<td>" + projectTasks[i].motusEmpInfoByUserId.name+ "</td>" +
					"<td>" + projectTasks[i].taskPlanStartTime + "</td>" +
					"<td>" + projectTasks[i].taskPlanEndTime + "</td>" +
					"<td>" + projectTasks[i].taskRealEndTime + "</td>" +
					"<td style='font-size: 12px;'><a href='checkEmpTask?taskId="+projectTasks[i].taskId+"' style='color:rgb(0,170,255);'><span class='glyphicon glyphicon-zoom-in'></span> 详情</a></td>" +
					"</tr>";
				$("#" + projectDivName).append(html);
			}
			
			for(var i = 0; i < meetingTasks.length; i++) {
				if(meetingTasks[i].taskRealStartTime == null) {
					meetingTasks[i].taskRealStartTime = "-";
				} else {
					meetingTasks[i].taskRealStartTime = meetingTasks[i].taskRealStartTime.replace("T", " ");
				}
				if(meetingTasks[i].taskRealEndTime == null) {
					meetingTasks[i].taskRealEndTime = "-";
				} else {
					meetingTasks[i].taskRealEndTime = meetingTasks[i].taskRealEndTime.replace("T", " ");
				}
				if(meetingTasks[i].taskPlanStartTime == null) {
					meetingTasks[i].taskPlanStartTime = "-";
				} else {
					meetingTasks[i].taskPlanStartTime = meetingTasks[i].taskPlanStartTime.replace("T", " ");
				}
				if(meetingTasks[i].taskPlanEndTime == null) {
					meetingTasks[i].taskPlanEndTime = "-";
				} else {
					meetingTasks[i].taskPlanEndTime = meetingTasks[i].taskPlanEndTime.replace("T", " ");
				}
				var html = "<tr><td>" + (i + 1) + "</td>" +
					"<td>" + meetingTasks[i].pmDeptTask.pmMeetingInfo.mname + "</td>" +
					"<td>" + meetingTasks[i].taskName + "</td>" +
					"<td>" + meetingTasks[i].motusEmpInfoByUserId.name + "</td>" +
					"<td>" + meetingTasks[i].taskPlanStartTime + "</td>" +
					"<td>" + meetingTasks[i].taskPlanEndTime + "</td>" +
					"<td>" + meetingTasks[i].taskRealStartTime + "</td>" +
					"<td>" + meetingTasks[i].taskRealEndTime + "</td>" +
					"<td>" + meetingTasks[i].taskTotalPoint + "</td>" +
					"</tr>";
				$("#" + meetingDivName).append(html);
			}
		}
	});

}